package com.tensquare.article.controller;

import com.tensquare.article.pojo.Article;
import com.tensquare.article.service.ArticleService;
import com.tensquare.entity.Result;
import com.tensquare.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zzb
 * @create 2021/2/21
 */
@RestController
@RequestMapping("article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;
    //文章审核
    @PutMapping("examine/{articleId}")
    public Result examine(@PathVariable String articleId){
        //文章审核
        articleService.examine(articleId);
        return new Result(true, StatusCode.OK,"文章审核通过");
    }

    //文章点赞
    @PutMapping("thumbup/{articleId}")
    public Result thumbup(@PathVariable String articleId){
        articleService.thumbup(articleId);
        return new Result(true,StatusCode.OK,"文章点赞成功");
    }

    //根据id查询文章
    @GetMapping("{articleId}")
    public Result findById(@PathVariable String articleId){
        articleService.findById(articleId);
        return new Result(true,StatusCode.OK,"查询文章成功");
    }

    //添加文章
    @PostMapping
    public Result add(@RequestBody Article article){
        articleService.add(article);
        return new Result(true,StatusCode.OK,"添加文章成功");
    }
}
